package com.lill.system.serivce.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lill.common.component.util.IdUtil;
import com.lill.system.dao.ISysRoleMenuDao;
import com.lill.system.service.ISysRoleMenuService;


/**
 * 角色与菜单对应关系
 *
 * @author lill
 */
@Service("sysRoleMenuService")
public class SysRoleMenuServiceImpl implements ISysRoleMenuService {
    @Autowired
    private ISysRoleMenuDao sysRoleMenuDao;

    @Transactional
    public void saveOrUpdate(String roleId, List<String> menuIdList) {
        if (menuIdList.size() == 0) {
            return;
        }
        //先删除角色与菜单关系
        sysRoleMenuDao.delete(roleId);

        //保存角色与菜单关系
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", IdUtil.createIdbyUUID());
        map.put("roleId", roleId);
        map.put("menuIdList", menuIdList);
        sysRoleMenuDao.save(map);
    }

    public List<String> queryDomainIdList(String roleId) {
        return sysRoleMenuDao.queryDomainIdList(roleId);
    }
    
    public List<String> queryMenuIdList(String roleId) {
    	return sysRoleMenuDao.queryMenuIdList(roleId);
    }

}
